home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / OTStreamLogViewer / IC Libraries / ICCommonSubs.h < prev    next >
Encoding:
Text File  |  2000-09-28  |  11.0 KB  |  312 lines  |  [TEXT/CWIE]

  1. /*    This file is part of the Internet Configuration system and is placed in the public domain for the benefit of all.
  2.  
  3.     This file holds all those miscellaneous little functions that are basically wrappers
  4.     around existing OS functionality.
  5. */
  6.  
  7. #import <Types.h>
  8. #import <Menus.h>
  9. #import "InternetConfig.h"
  10.  
  11. /* ***** Event Manager Stuff ***** */
  12.  
  13. /* A collection of useful ASCII character definitions. */            
  14.  
  15. enum {
  16.     kNulChar            = 0x000,
  17.     kHomeChar             = 0x001,
  18.     kEnterChar             = 0x003,
  19.     kEndChar             = 0x004,
  20.     kHelpChar             = 0x005,
  21.     kBackSpaceChar         = 0x008,
  22.     kTabChar             = 0x009,
  23.     kLineFeedChar         = 0x00A,
  24.     kPageUpChar         = 0x00B,
  25.     kPageDownChar         = 0x00C,
  26.     kCRChar             = 0x00D,
  27.     kEscChar             = 0x01B,
  28.     kClearChar             = 0x01B,
  29.     kLeftArrowChar         = 0x01C,
  30.     kRightArrowChar     = 0x01D,
  31.     kUpArrowChar         = 0x01E,
  32.     kDownArrowChar        = 0x01F,
  33.     kSpaceChar             = 0x020,
  34.     kDelChar             = 0x07F,
  35.     kBulletChar         = 0x0A5
  36. };
  37.  
  38. /* A collection of useful virtual key code definitions. */            
  39.  
  40. enum {
  41.     kUndoKeyCode         = 122,
  42.     kCutKeyCode         = 120,
  43.     kCopyKeyCode         = 99,
  44.     kPasteKeyCode         = 118,
  45.     kClearKeyCode         = 71,
  46.  
  47.     kEscKeyCode         = 53,
  48.     kReturnKeyCode         = 36,
  49.     kEnterKeyCode         = 52,
  50.     kTabKeyCode         = 48,
  51.     kSpaceKeyCode        = 49,
  52.     KDeleteKeyCode         = 51,
  53.  
  54.     kCommandKeyCode     = 55,
  55.     kShiftKeyCode         = 56,
  56.     kCapsLockKeyCode     = 57,
  57.     kOptionKeyCode         = 58
  58. };
  59.  
  60. /* ***** Memory Stuff ***** */
  61.  
  62. enum {
  63.     kHandleLockBit = 7,
  64.     kHandlePurgeBit = 6,
  65.     kHandleResourceBit = 5,
  66.     
  67.     kHandleLockMask = 0x080,
  68.     kHandlePurgeMask = 0x040,
  69.     kHandleResourceMask = 0x020
  70. };
  71.  
  72. #if 0
  73.  
  74. // These types are probably unnecessary for C.
  75.  
  76. type
  77.     /* A data structure for addresses memory as bytes. */
  78.     BigBuffer = packed array [0..$0FFFFFF] of UInt8;
  79.     BigBufferPtr = ^BigBuffer;
  80.     BigBufferHandle = ^BigBufferPtr;
  81.  
  82.     /* Another for addressing memory as chars. */
  83.     BigCharArray = packed array [0..$FFFFFF] of char;
  84.     BigCharArrayPtr = ^BigCharArray;
  85.     BigCharArrayHandle = ^BigCharArrayPtr;
  86.  
  87. #endif
  88.  
  89. extern pascal Boolean BlockCompare (void *lhsBaseAddr, void *rhsBaseAddr, SInt32 size);
  90.     /* Compares two blocks of memory for equality.*/
  91.     
  92. extern pascal void BlockFill (void *baseAddr, SInt32 size, SInt16 value);
  93.     /* Fills a block of memory with the value.  The memory is filled
  94.         as bytes, ie the high byte of value is ignored.
  95.     */
  96.  
  97. /* ***** Resource Manager Stuff ***** */
  98.  
  99. extern pascal ICError CheckMemError(Handle memoryHandle);
  100. extern pascal ICError CheckResError(Handle resourceHandle);
  101.  
  102. extern pascal ICError AddNamedResource(Handle data, ResType theType, ConstStr255Param name);
  103.     /*    Adds data to the current resource file as a resource
  104.         of type theType with the given name.  It calculates a
  105.         unique resource ID for the newly added resource.  Note that,
  106.         like AddResource, data comes back as either a resource
  107.         handle (on noErr) or still a memory handle (on error).
  108.     */
  109.     
  110. extern pascal OSStatus Set1Resource(Handle theData, ResType theType, SInt16 theID);
  111.     /*    This routine sets the resource denoted by theType and theID to contain
  112.         theData.  If the resource does not currently exist, it is created.
  113.         If it does currently exist, it is modified.  theData is not disposed
  114.         of.
  115.     */
  116. extern pascal OSStatus Set1ResourcePtr(void *theData, SInt32 theDataSize, ResType theType, SInt16 theID);
  117.     /*    Works like Set1Resource except that you pass in a pointer and size. */
  118.  
  119. extern pascal OSStatus Set1NamedResource(Handle theData, ResType theType, ConstStr255Param name);
  120.     /*    This routine sets the resource denoted by theType and name to contain
  121.         theData.  If the resource does not currently exist, it is created with
  122.         a unique ID greater than 127.  If it does currently exist, it is modified.
  123.         theData is not disposed of.
  124.     */
  125.  
  126. /* ***** File Manager Stuff ***** */
  127.  
  128. extern pascal OSStatus GetVolInfo (Str63 ioName, SInt16 *ioVRefNum, SInt16 ioVolIndex,
  129.                                     SInt32 ioVCrDate);
  130.     /* Returns information about the specified volume. Basically this is a wrapper
  131.         around PBGetVInfo.  See Files IM for a description of the meaning of the
  132.         ioName, ioVRefNum and ioVolIndex parameters.  This routine also returns
  133.         the volume's creation date in ioVCrDate to aid in Poor Man's Alias Manager
  134.         volume matching.
  135.     */
  136.     
  137. extern pascal OSStatus FindApplicationInDTDB (OSType creator, FSSpec *foundApplicationSpec);
  138.     /* This routine attempts to find an application in the desktop database
  139.         given its creator type.
  140.     */
  141.     
  142. extern pascal OSStatus FSpGetCatInfo (FSSpec *fss, SInt16 ioFDirIndex, CInfoPBRec *cpb);
  143.     /* This routine is a simple wrapper around PBGetCatInfo.  See Files IM
  144.         for a description of the meaning of ioFDirIndex.
  145.         Note that, despite the name, this routine can be called under System 6.
  146.     */
  147.     
  148. extern pascal OSStatus FSpSetCatInfo (FSSpec *fss, CInfoPBRec *cpb);
  149.     /* This routine is a simple wrapper around PBSetCatInfo.
  150.         Note that, despite the name, this routine can be called under System 6.
  151.     */
  152.     
  153. extern pascal OSStatus FSpCatMoveQ(FSSpec *fss, SInt32 destDirID);
  154.     /*    A nicer wrapper around PBCatMove.  FSpCatMove is a horrible
  155.         routine because it requires a dest FSSpec, rather than
  156.         a dest dirID.  CatMove is not good either because the
  157.         Pascal interfaces define it to take a Str255 var rather
  158.         than a StringPtr, so you can't pass nil for ioNewName.
  159.         So instead, we write our own.
  160.     */
  161.  
  162. extern pascal OSStatus FileLocked (const FSSpec *fss);
  163.     /* This routine returns true if the specified file is locked. Note that
  164.         this provides no guarantee that you can write to the file, it merely
  165.         checks all the things it can to see if any of them disable writing.
  166.     */
  167.     
  168. extern pascal OSStatus CopyFork (SInt16 sourceForkRefnum, SInt16 destForkRefnum, SInt32 bytesToCopy);
  169.     /* This routine copies a file fork from sourceForkRefnum to destForkRefnum.
  170.         The files must be positioned at where you want to start copying (usually
  171.         at the beginning) and the routine copys bytesToCopy bytes from the source
  172.         to the destination.
  173.     */
  174.  
  175. extern pascal OSStatus CopyForkToFork (FSSpec *sourceFile, FSSpec *destFile,
  176.                         Boolean sourceRsrc, Boolean destRsrc);
  177.     /* This routine copies a fork from the sourceFile to the destFile.
  178.         The fork chosen in each case is determined by the sourceRsrc and
  179.         destRsrc switches.  If true, the resource fork is used, if false,
  180.         the data fork.
  181.     */
  182.  
  183. extern pascal OSStatus CopyFile (FSSpec *source, FSSpec *dest);
  184.     /* Copies a file from source to dest.  Any file already existing at dest is
  185.         destroyed.  Also set the catalogue info for the dest file from the source file.
  186.     */
  187.  
  188. extern pascal OSStatus GetFSSpecGivenFileRefNum(SInt16 fileRefNum, FSSpec *fss);
  189.     /* Consults the FCB of the open file to find out its FSSpec. */
  190.  
  191. extern pascal OSStatus FileRefNumIsWriteable(SInt16 fileRefNum, Boolean *writeable);
  192.     /* Returns true if the FCB says that the file is writable. */
  193.  
  194. extern pascal Boolean EqualFSSpec(const FSSpec *fss1, const FSSpec *fss2);
  195.     /* Returns true if fss1 and fss2 denote the same file system object. */
  196.  
  197. extern pascal OSErr ICUFSSpecToFullPath (const FSSpec fss, Str255 path);
  198.     /* Returns a full path for the given FSSpec.  Actually it's an approximation
  199.         (it doesn't handle paths longer than 256 characters) but, seeing as
  200.         IC only uses this path for display purposes, that's not a problem.
  201.     */
  202.  
  203. extern pascal ICError ICFileSpecToFSSpec (ICFileSpecHandle fileSpec, Boolean canInteract, FSSpec *fss);
  204. extern pascal OSErr FSSpecToICFileSpec (FSSpec *fss, ICFileSpecHandle fileSpec);
  205.     /* These routines convert ICFileSpecHandles to FSSpecs and vice versa.
  206.         An ICFileSpecHandle is basically an AliasHandle with some fields tacked
  207.         on the front to make it usable by System 6 clients.  Under System 7 these
  208.         routines are basically wrappers for standard Alias Manager routines.
  209.         Note that in poth of these routines, the caller is responsible for allocating
  210.         and deallocating the ICFileSpecHandle, and we just resize it if necessary.
  211.     */
  212.  
  213. extern pascal Boolean IsApplicationType(OSType fdType);
  214.     /*    Returns true if fdType is common type for applications. */
  215.  
  216. /* ***** IC API Stuff ***** */
  217.  
  218. /* These are simple wrappers around the IC API for getting and setting PString preferences. */
  219.  
  220. extern pascal ICError ICGetPrefStr (ICInstance inst, ConstStr255Param key, ICAttr *attr, Str255 str);
  221. extern pascal ICError ICSetPrefStr (ICInstance inst, ConstStr255Param key, ICAttr attr, ConstStr255Param str);
  222.  
  223. /* ***** Text Utilities Stuff ***** */
  224.  
  225. /* These are simple wrappers around the toolbox NumToString and StringToNum routines. */
  226.  
  227. #if 0
  228. // No point having this is C because you can't return a Str255,
  229. // and the obvious conversion is no advantage over NumToString.
  230. extern pascal Str255 DecStr(SInt32 aNumber);
  231. #endif
  232.  
  233. extern pascal SInt32 DecVal(ConstStr255Param aString);
  234.  
  235.  
  236. /* These are simple routines to convert between strings and OSTypes. */
  237.  
  238. extern pascal OSType StringToOSType (ConstStr255Param aString);
  239.  
  240. #if 0
  241. extern pascal Str15 OSTypeToString (OSType anOSType);
  242.  
  243. extern pascal Str255 TPCopy (ConstStr255Param sourceString, SInt16 startIndex, SInt16 count);
  244.     /* TPCopy provides a version of the Pascal built-in function Copy that
  245.         implements the Think Pascal semantics.  This is much more useful
  246.         than routine built-in to Metrowerks Pascal, which implements the
  247.         semantics of MPW Pascal.
  248.         The routine extracts count characters from the source string
  249.         starting at character position start.  If there aren't enough characters
  250.         in the string, it returns what there are.
  251.     */
  252.  
  253. extern pascal Str255 GetOwnerName(void);
  254.     /* This function returns the Owner name for the Macintosh
  255.         as defined in the Sharing Setup control panel.
  256.     */
  257.     
  258. extern pascal Str255 NewLookupError(SInt16 NersID, OSStatus errNum);
  259. /* Return the string associated with errNum.  The 'Ners' resource
  260.     has a ResEdit template of...
  261.             *****
  262.             LSTB
  263.                 errNum
  264.                 DLNG
  265.                 errstr
  266.                 PSTR
  267.             *****
  268.             LSTE
  269.     There must be a terminating entry with error number of 0 that contains
  270.     the default error message.
  271. */
  272.  
  273. #endif
  274.  
  275. extern pascal void NewLookupErrorC(SInt16 NersID, OSStatus errNum, Str255 result);
  276. /* A procedure version of the above, for access from lame C-like
  277.     languages.
  278. */
  279.     
  280. /* ***** Truly Misc Stuff ***** */
  281.  
  282. extern pascal Boolean TrapAvailable (SInt16 theTrap);
  283.     /* Returns true if theTrap is available on this machine.
  284.         This routine is implemented by the book, the book being Inside Macintosh.
  285.     */
  286.  
  287. #if ! GENERATINGCFM
  288.  
  289. extern pascal void MakeDataExecutableAs68KCode(void *base, SInt32 size);
  290.     /* Makes some data executable as 68K code.  This is distinct
  291.         from the system call MakeDataExecutable, which makes data
  292.         executable as PowerPC code.
  293.        This call makes sense even on PPC machines, for example
  294.           the old contents of the memory might be currently cached
  295.           in the DR (Dynamic Recompiling) translation cache.
  296.     */
  297.  
  298. #endif
  299.  
  300. extern pascal ICError ICUCanInteract(void);
  301.     /* Returns noErr if user interaction is possible.  Basically a wrapper
  302.         around AEInteractWithUser that makes it System 6 safe.
  303.     */
  304.  
  305. extern pascal void SafeAppendMenu (MenuHandle menuH, ConstStr255Param itemText);
  306.     /* The system AppendMenu interprets the new menu item in strange
  307.         ways, attempting to glean command key and other information from 
  308.         the text.  This is obviously bad for things like the items on the 
  309.         Archie menu.  This 'safe' version of the AppendMenu routine
  310.         sets the text window interpreting it.
  311.     */
  312.